﻿{extend name="base"/}
{block name="main"}
<div class="Hui-article">
    <article class="cl pd-20">
        <div class="n_tab_line">
           <a href="{:url('goods/goodslist')}" class="n_tab_list">相册列表</a>
            <!---->
             <a onclick="images_add('创建相册','__CONF_SITE__admin/Images/images_add',400,300)" href="javascript:;" class="n_tab_add"><i class="Hui-iconfont">&#xe600;</i>创建相册</a>
            <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px;display: none;" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
            <div class="cl"></div>
       </div>
       <!--<div id="tab_demo" class="HuiTab" style="margin-top: 0px; position: relative;">
            <div class="tabBar clearfix">
                <span  class="current" onclick="window.location.href='{:url('goods/goodslist')}'">相册列表</span>
                <div class="l n_tab_add"><a href="javascript:;" onclick="images_add('创建相册','images_add')">创建相册</a></div>
            </div>
        </div>-->
            
    <div class="cl pd-5 bg-1 bk-gray mt-20">
                <form class="Huiform" method="post" action="__CONF_SITE__admin/images/image_list" target="_self" style=" padding: 15px;">
                    <div class="text-c"> 相册名称：
                      <input type="text" name="search_text" value="{$search_text}" id="a" placeholder="相册名称" style="width:250px" class="input-text">
                        <button class="btn btn-search radius" type="submit"><i class="Hui-iconfont">&#xe665;</i> 搜相册</button>
                    </div>
                </form>

<!--
                    <span class="l">
                        <a class="btn btn-primary radius" onclick="images_add('创建相册','images_add')" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 创建相册</a>
                    </span>
-->
                </div>
                <div class="mt-20">
                    <table class="table table-border table-bordered table-bg table-hover table-sort">
                        <thead>
                        <tr class="text-c">
                            <th width="16%">名称</th>
                            <th>封面</th>
                            <th>图片数量</th>
                            <th>添加时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {volist name="retval" id="r"}
                        <tr class="text-c">
                            <td>
                                {if $r.group_name != '默认相册'}
                                    <input value="{$r['group_name']}" class="input-text" style="height: 30px;width: 150px;padding-left: 5px;text-align: center"
                                       data-value="{$r['group_name']}"
                                       onblur="silent_save('{$r.group_id}',this)">
                                {else}
                                    {$r.group_name}
                                {/if}
                            </td>
                            <td>
                                <a href="javascript:;" onClick="images_edit('图库编辑','__CONF_SITE__admin/Images/images_edit&search_text={$r.group_id}','100%','100%')">
                                    {if isset($r['img_info'])&&$r['img_info']['img_cover']!=''}
                                        <img width="60" height="60" class="radius" src="{$r['img_info']['img_cover']}">
                                    {else}
                                         <img width="60" height="60" class="radius" src="/public/goods/img/default_goods_image_240.gif">
                                    {/if}
                                </a>
                            </td>
                            <td>{$r['img_count']}</td>
                            <td>{$r['create_time']}</td>
                            <td class="td-manage">
                                <a style="text-decoration:none;text-decoration:none;color:#0066cc;" class="ml-5" onClick="images_edit('图库编辑','__CONF_SITE__admin/Images/images_edit&search_text={$r.group_id}','100%','100%')" href="javascript:;" title="管理">管理
<!--                                <i class="Hui-iconfont">&#xe6df;</i>-->
                                </a>
                                {if $r['is_default']!=1}
                                <a style="text-decoration:none;text-decoration:none;color:#0066cc;" class="ml-5" onClick="images_del(this,'{$r.group_id}')" href="javascript:;" title="删除">删除
<!--                                s-->
                                </a></td>
                                {/if}
                        </tr>
                        {/volist}
                        </tbody>
                    </table>
                    <div class="n_page_no">
                        {$page}
                    </div>
                </div>
            </article>
        </div>
{/block}
{block name="script"}
<script type="text/javascript">
	/*
	 参数解释：
	 title	标题
	 url		请求的url
	 id		需要操作的数据id
	 w		弹出层宽度（缺省调默认值）
	 h		弹出层高度（缺省调默认值）
	 */
	/*相册-添加*/
    function images_add(title,url,w,h){
        layer_show(title,url,w,h);
    }
    /*相册-编辑*/
    function images_edit(title,url,w,h){
        layer.open({
            type: 2,
            area: [w, h],
            fix: false, //不固定
            maxmin: true,
            shade:0.4,
            title: title,
            content: url,
            scrollbar:false
        });
    }
    function silent_save(id, obj) {
        var data_value = $(obj).attr('data-value');
        if(obj.value != data_value){
            $.ajax({
                type: "post",
                url: "{:url('images/silent')}",
                data: {
                    id: id,
                    name: obj.value,
                },
                success: function (data) {
                    if (data['code'] > 0) {
                        $(obj).attr('data-value', obj.value);
                        layer.msg('保存成功', {icon: 1, time: 1000});
                    } else {
                        $(obj).val(data_value);
                        layer.msg('保存失败', {icon: 2, time: 1000});
                    }
                }
            });
        }
    }
    /*相册-删除*/
    function images_del(obj,id) {
        layer.confirm('删除相册会连带相册图片一并删除！',function(index){
            //此处请求后台程序
            //后台处理
            $.ajax({
                type : "post",
                url : "{:url('images/imagesDel')}",
                data : {
                    "img_id" : id,
                },
                success : function(data) {
                    if (data['code'] > 0) {
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!',{icon:1,time:1000});
                    }else{
                        layer.msg(data['message'], {icon: 2, time: 1000});
                    }
                }
            })
        });
    }
</script>
{/block}